package cn.fetosoft.rooster.demo.job;

import org.quartz.*;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @Title：打印定时
 * @Author：guobingbing
 * @Date 2020/1/22 16:50
 * @Description
 * @Version
 */

/**
 * 此处可省略Spring的@Component注解
 */
@DisallowConcurrentExecution
public class PrintJob implements Job {

	/**
	 *
	 */
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		JobDetail jobDetail = context.getJobDetail();
		JobDataMap map = jobDetail.getJobDataMap();
		try {
			TimeUnit.MILLISECONDS.sleep(new Random().nextInt(3000));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		//打印map中的所有参数
		Iterator<Map.Entry<String, Object>> iter = map.entrySet().iterator();
		while (iter.hasNext()){
			Map.Entry<String, Object> entry = iter.next();
			System.out.println(entry.getKey() + "=" + entry.getValue());
		}
	}
}
